import 'dart:async';

import 'package:flutter/material.dart';


///防抖
class DebounceBtn extends StatefulWidget {
  const DebounceBtn({super.key, required this.onTap, required this.child});
  final Function onTap;
  final Widget child;
  @override
  State<DebounceBtn> createState() => _DebounceBtnState();
}

class _DebounceBtnState extends State<DebounceBtn> {
  bool _canClick = true;
  onTap() {
    if (_canClick) {
      widget.onTap();
      _canClick = false;
      Future.delayed(const Duration(milliseconds: 500), () {
        _canClick = true;
      });
    }
  }
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onTap,
      child: widget.child,
    );
  }
}
